Skip to content

Conversation

@mchain0
Copy link
Contributor

@mchain0 mchain0 commented Nov 18, 2025

CRE-1325

Adds deadline-aware timeout handling for channel operations, preventing indefinite blocking and silent message drops when requests expire.

@mchain0 mchain0 requested a review from a team as a code owner November 18, 2025 09:11
@github-actions
Copy link

👋 mchain0, thanks for creating this pull request!

To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team.

Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks!

@github-actions
Copy link

github-actions bot commented Nov 18, 2025

✅ API Diff Results - No breaking changes


📄 View full apidiff report

Err: fmt.Errorf("requested seqNum %d for executionID %s is greater than the number of observed don times %d",
req.SeqNum, req.WorkflowExecutionID, numObservedDonTimes),
})
cancel()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you want to achieve with this cancel? The SendRepsonse is a sync function that either succeeds or fails. Calling cancel() afterwards does not seem to do anything.

return nil, nil
}

func (p *Plugin) Observation(_ context.Context, outctx ocr3types.OutcomeContext, query types.Query) (types.Observation, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this parent context be used?

Suggested change
func (p *Plugin) Observation(ctx context.Context, outctx ocr3types.OutcomeContext, query types.Query) (types.Observation, error) {

Comment on lines +33 to +39
// Don't block if receiver not ready, but check if context is actually expired
select {
case <-ctx.Done():
// Context cancelled or deadline exceeded before send
default:
// Try once more without blocking
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just check for an error instead of using the channel mechanism:

Suggested change
// Don't block if receiver not ready, but check if context is actually expired
select {
case <-ctx.Done():
// Context cancelled or deadline exceeded before send
default:
// Try once more without blocking
}
// Don't block if receiver not ready, but check if context is actually expired
ctx.Err()

But what is meant to happen here? Both cases are no-ops.

Comment on lines +92 to +101
ctx, cancel := context.WithDeadline(context.Background(), req.ExpiryTime())
req.SendResponse(ctx,
Response{
WorkflowExecutionID: req.WorkflowExecutionID,
SeqNum: req.SeqNum,
Timestamp: 0,
Err: fmt.Errorf("requested seqNum %d for executionID %s is greater than the number of observed don times %d",
req.SeqNum, req.WorkflowExecutionID, numObservedDonTimes),
})
cancel()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: @pavel-raykov - you can use anonymous closures to reduce scope of deferred actions:

Suggested change
ctx, cancel := context.WithDeadline(context.Background(), req.ExpiryTime())
req.SendResponse(ctx,
Response{
WorkflowExecutionID: req.WorkflowExecutionID,
SeqNum: req.SeqNum,
Timestamp: 0,
Err: fmt.Errorf("requested seqNum %d for executionID %s is greater than the number of observed don times %d",
req.SeqNum, req.WorkflowExecutionID, numObservedDonTimes),
})
cancel()
func() {
ctx, cancel := context.WithDeadline(context.Background(), req.ExpiryTime())
defer cancel()
req.SendResponse(ctx,
Response{
WorkflowExecutionID: req.WorkflowExecutionID,
SeqNum: req.SeqNum,
Timestamp: 0,
Err: fmt.Errorf("requested seqNum %d for executionID %s is greater than the number of observed don times %d",
req.SeqNum, req.WorkflowExecutionID, numObservedDonTimes),
})
} ()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants